package com.bishe.demo.modules.common.service.impl;

import com.bishe.demo.modules.common.dao.CityDao;
import com.bishe.demo.modules.common.entity.City;
import com.bishe.demo.modules.common.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityServiceImpl implements CityService {
    @Autowired
    private CityDao cityDao;

    @Override
    public List<City> getCities() {
        List<City> provinces = cityDao.getCitiesByPid(0);
        for (City province : provinces) {
            List<City> cities = cityDao.getCitiesByPid(province.getId());
            for (City city : cities) {
                List<City> area = cityDao.getCitiesByPid(city.getId());
                city.setCities(area);
            }
            province.setCities(cities);
        }
        return provinces;
    }

    @Override
    public List<City> getCitiesByPid(int pid) {
        return cityDao.getCitiesByPid(pid);
    }

}
